{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "conservative-automation",
   "metadata": {},
   "source": [
    "https://leetcode.com/problems/find-and-replace-pattern/\n",
    "\n",
    "\n",
    "Runtime: 24 ms, faster than 98.34% of Python3 online submissions for Find and Replace Pattern.\n",
    "Memory Usage: 14.4 MB, less than 34.06% of Python3 online submissions for Find and Replace Pattern.\n",
    "\n",
    "\n",
    "```python\n",
    "class Solution:\n",
    "    def findAndReplacePattern(self, words: List[str], pattern: str) -> List[str]:\n",
    "        #7:10\n",
    "        def get_pattern(s):\n",
    "            name_map = dict()\n",
    "            counter = dict()\n",
    "            name_list = list()\n",
    "            i = 0\n",
    "            for c in s:\n",
    "                if c in counter:\n",
    "                    counter[c] += 1\n",
    "                else:\n",
    "                    counter[c] = 1\n",
    "                    name_map[c] = i\n",
    "                    i += 1\n",
    "                name_list.append(name_map[c])\n",
    "            #return [(key, counter[value]) for key,value in name_map.items()]\n",
    "            return name_list\n",
    "        target_pattern = get_pattern(pattern)\n",
    "        results = []\n",
    "        for word in words:\n",
    "            pattern = get_pattern(word)\n",
    "            if pattern == target_pattern:\n",
    "                results.append(word)\n",
    "        return results\n",
    "        #7:24\n",
    "        #made by yingshaoxo: https://github.com/yingshaoxo\n",
    "```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "neither-pizza",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
